/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import com.google.code.morphia.dao.BasicDAO;
import entity.Tag;
import org.bson.types.ObjectId;

/**
 *
 * @author xuanhung2401
 */
public class TagModel extends BasicDAO<Tag, ObjectId>{    
	public TagModel() {
        super(DBConnection.getMongo(), DBConnection.getMorphia(), DBConnection.getDatabase());
        ds.ensureIndexes();
    }
    
    public Tag findByAlias(String alias) {
        return ds.find(Tag.class, "alias", alias).get();
    }
    @SuppressWarnings("deprecation")
	public Tag random() {
		long min = 1;
		long max = 6000;
		long random = min + (int) (Math.random() * (max - min));		
		return ds.find(Tag.class).limit(-1).skip((int) random).get();		
	}
    
    public static void main(String[] args){
    	TagModel model = new TagModel();
    	System.out.println(model.random().getAlias());
    }
}
